# coding:utf-8
'''
Created on 2015年6月29日

@author: Emrys
'''

from functools import wraps


class lazyproperty:

    def __init__(self, func):
        self.func = func
#         wraps(func)(self)

    def __get__(self, instance, cls):
        if instance is None:
            return self
        else:
            value = self.func(instance)
            setattr(instance, self.func.__name__, value)
            return value

import math


class Circle:

    def __init__(self, radius):
        self.radius = radius

    @lazyproperty
    def area(self):
        print("Computing area")
        return math.pi * self.radius

    @lazyproperty
    def perimeter(self):
        print('Computing perimeter')
        return 2 * math.pi * self.radius


c = Circle(4.0)
print(c.radius)
print(c.radius)
print(c.area)
print(c.area)
